SuperStrict

Framework arm.box2d
Import BRL.GLMax2D

Import "framework/test.bmx"


Graphics 800,600, 0
SetBlend alphablend


Run(New VaryingRestitution.Create(), New TSettings)

Type VaryingRestitution Extends Test

	Method Create:VaryingRestitution()
	
		Init(20, 20)
		
		' Create Ground
		Local groundShape:b2PolygonShape = New b2PolygonShape
		groundShape.SetAsOrientedBox(50.0, 10.0, New b2Vec2.Create(0.0, -10.0), 0)

		Local groundBodyDef:b2BodyDef = New b2BodyDef

		Local groundBody:b2Body = m_world.CreateBody(groundBodyDef)
		groundBody._CreateFixture(groundShape, 0.0)

		' Create Circles

		local cShape:b2CircleShape = New b2CircleShape
		cShape.SetRadius(1.0)
		
		Local cFixtureDef:b2FixtureDef = New b2FixtureDef
		cFixtureDef.SetShape(cShape)
		cFixtureDef.SetDensity(1.0)
		
		' Note:even with a restitution of 1.0, there is some energy change due to position correction.
		Local restitution:Float[] = [0.0, 0.1, 0.3, 0.5, 0.75, 0.9, 1.0]

		For Local i:Int = 0 Until 7


			local cBodyDef:b2BodyDef = New b2BodyDef
			cBodyDef.SetPositionXY(-10.0 + 3.0 * i, 20.0)
			cBodyDef.SetType(b2_dynamicBody)
			
			cFixtureDef.SetRestitution(restitution[i])

			Local circleBody:b2Body = m_world.CreateBody(cBodyDef)
			circleBody.CreateFixture(cFixtureDef)
			
		Next

		Return Self
		
	End Method

End Type

